package com.xk857.school.mapper;

import com.xk857.entities.Card;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author CV大魔王
 * @since 2021-05-02
 */
public interface CardMapper extends BaseMapper<Card> {

    /**
     * 本月校园卡信息发布数量
     *
     * @return 校园卡信息发布数量
     */
    @Select("SELECT count(id) FROM  school_card WHERE DATE_FORMAT(create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) ,'%Y%m' ) ")
    Integer queryCountMonth();


    /**
     * 上月校园卡信息发布数量
     *
     * @return 校园卡信息发布数量
     */
    @Select("SELECT count(id) FROM school_card WHERE PERIOD_DIFF( date_format( now( ) , '%Y%m' ) , date_format( create_time, '%Y%m' ) ) =1")
    Integer queryCountFirstMonth();


    /**
     * 本周校园卡信息发布数量
     *
     * @return 校园卡信息发布数量
     */
    @Select("SELECT  count(id) FROM  school_card WHERE YEARWEEK( date_format(  create_time,'%Y-%m-%d' ) ) = YEARWEEK( now() ) ")
    Integer queryCountWeek();


    /**
     * 上周校园卡信息发布数量
     *
     * @return 校园卡信息发布数量
     */
    @Select("SELECT  count(id) FROM  school_card WHERE YEARWEEK( date_format(  create_time,'%Y-%m-%d' ) ) = YEARWEEK( now() ) -1")
    Integer queryCountFirstWeek();
}
